home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / CIncludes / DatabaseAccess.h < prev    next >
C/C++ Source or Header  |  1996-05-01  |  13KB  |  326 lines

  1. /*
  2.      File:        DatabaseAccess.h
  3.  
  4.      Contains:    Database Access Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0d3 on Copland DR1
  8.  
  9.      Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  10.  
  11.      Bugs?:        If you find a problem with this file, send the file and version
  12.                  information (from above) and the problem description to:
  13.  
  14.                      Internet:    apple.bugs@applelink.apple.com
  15.                      AppleLink:    APPLE.BUGS
  16.  
  17. */
  18. #ifndef __DATABASEACCESS__
  19. #define __DATABASEACCESS__
  20.  
  21. #ifndef __RESOURCES__
  22. #include <Resources.h>
  23. #endif
  24.  
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28.  
  29. #if PRAGMA_IMPORT_SUPPORTED
  30. #pragma import on
  31. #endif
  32.  
  33. #if PRAGMA_ALIGN_SUPPORTED
  34. #pragma options align=mac68k
  35. #endif
  36.  
  37. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  38. /* data type codes */
  39.  
  40. enum {
  41.     typeNone                    = 'none',
  42.     typeDate                    = 'date',
  43.     typeTime                    = 'time',
  44.     typeTimeStamp                = 'tims',
  45.     typeDecimal                    = 'deci',
  46.     typeMoney                    = 'mone',
  47.     typeVChar                    = 'vcha',
  48.     typeVBin                    = 'vbin',
  49.     typeLChar                    = 'lcha',
  50.     typeLBin                    = 'lbin',
  51.     typeDiscard                    = 'disc',                        /* "dummy" types for DBResultsToText */
  52.     typeUnknown                    = 'unkn',
  53.     typeColBreak                = 'colb',
  54.     typeRowBreak                = 'rowb',                        /* pass this in to DBGetItem for any data type */
  55.     typeAnyType                    = 0
  56. };
  57.  
  58. /* infinite timeout value for DBGetItem */
  59.  
  60. enum {
  61.                                                                 /* messages for status functions for DBStartQuery */
  62.     kDBUpdateWind                = 0,
  63.     kDBAboutToInit                = 1,
  64.     kDBInitComplete                = 2,
  65.     kDBSendComplete                = 3,
  66.     kDBExecComplete                = 4,
  67.     kDBStartQueryComplete        = 5
  68. };
  69.  
  70.  
  71. enum {
  72.                                                                 /* messages for status functions for DBGetQueryResults */
  73.     kDBGetItemComplete            = 6,
  74.     kDBGetQueryResultsComplete    = 7,
  75.     kDBWaitForever                = -1,                            /*  flags for DBGetItem  */
  76.     kDBLastColFlag                = 0x0001,
  77.     kDBNullFlag                    = 0x0004
  78. };
  79.  
  80. typedef OSType DBType;
  81. typedef struct DBAsyncParamBlockRec DBAsyncParamBlockRec;
  82. typedef DBAsyncParamBlockRec *DBAsyncParmBlkPtr;
  83. /*
  84.         This ProcPtr uses register based parameters on the 68k and cannot
  85.         be written in or called from a high-level language without the help of
  86.         mixed mode or assembly glue.
  87.  
  88.             typedef pascal void (*DBCompletionProcPtr)(DBAsyncParmBlkPtr pb);
  89.  
  90. */
  91.  
  92. #if GENERATINGCFM
  93. typedef UniversalProcPtr DBCompletionUPP;
  94. #else
  95. typedef Register68kProcPtr DBCompletionUPP;
  96. #endif
  97. /* structure for asynchronous parameter block */
  98. struct DBAsyncParamBlockRec {
  99.     DBCompletionUPP                 completionProc;                /* pointer to completion routine */
  100.     OSErr                             result;                        /* result of call */
  101.     long                             userRef;                    /* for application's use */
  102.     long                             ddevRef;                    /* for ddev's use */
  103.     long                             reserved;                    /* for internal use */
  104. };
  105.  
  106. /* structure for resource list in QueryRecord */
  107. struct ResListElem {
  108.     ResType                         theType;                    /* resource type */
  109.     short                             id;                            /* resource id */
  110. };
  111. typedef struct ResListElem ResListElem;
  112.  
  113. typedef ResListElem *ResListPtr;
  114. typedef ResListPtr *ResListHandle;
  115. /* structure for query list in QueryRecord */
  116. typedef Handle QueryArray[256];
  117. typedef Handle *QueryListPtr;
  118. typedef QueryListPtr *QueryListHandle;
  119. struct QueryRecord {
  120.     short                             version;                    /* version */
  121.     short                             id;                            /* id of 'qrsc' this came from */
  122.     Handle                             queryProc;                    /* handle to query def proc */
  123.     Str63                             ddevName;                    /* ddev name */
  124.     Str255                             host;                        /* host name */
  125.     Str255                             user;                        /* user name */
  126.     Str255                             password;                    /* password */
  127.     Str255                             connStr;                    /* connection string */
  128.     short                             currQuery;                    /* index of current query */
  129.     short                             numQueries;                    /* number of queries in list */
  130.     QueryListHandle                 queryList;                    /* handle to array of handles to text */
  131.     short                             numRes;                        /* number of resources in list */
  132.     ResListHandle                     resList;                    /* handle to array of resource list elements */
  133.     Handle                             dataHandle;                    /* for use by query def proc */
  134.     long                             refCon;                        /* for use by application */
  135. };
  136. typedef struct QueryRecord QueryRecord;
  137.  
  138. typedef QueryRecord *QueryPtr;
  139. typedef QueryPtr *QueryHandle;
  140. /* structure of column types array in ResultsRecord */
  141. typedef DBType ColTypesArray[256];
  142. typedef Handle ColTypesHandle;
  143. /* structure for column info in ResultsRecord */
  144. struct DBColInfoRecord {
  145.     short                             len;
  146.     short                             places;
  147.     short                             flags;
  148. };
  149. typedef struct DBColInfoRecord DBColInfoRecord;
  150.  
  151. typedef DBColInfoRecord ColInfoArray[256];
  152. typedef Handle ColInfoHandle;
  153. /* structure of results returned by DBGetResults */
  154. struct ResultsRecord {
  155.     short                             numRows;                    /* number of rows in result */
  156.     short                             numCols;                    /* number of columns per row */
  157.     ColTypesHandle                     colTypes;                    /* data type array */
  158.     Handle                             colData;                    /* actual results */
  159.     ColInfoHandle                     colInfo;                    /* DBColInfoRecord array */
  160. };
  161. typedef struct ResultsRecord ResultsRecord;
  162.  
  163. typedef pascal OSErr (*DBQueryDefProcPtr)(long *sessID, QueryHandle query);
  164. typedef pascal Boolean (*DBStatusProcPtr)(short message, OSErr result, short dataLen, short dataPlaces, short dataFlags, DBType dataType, Ptr dataPtr);
  165. typedef pascal OSErr (*DBResultHandlerProcPtr)(DBType dataType, short theLen, short thePlaces, short theFlags, Ptr theData, Handle theText);
  166.  
  167. #if GENERATINGCFM
  168. typedef UniversalProcPtr DBQueryDefUPP;
  169. typedef UniversalProcPtr DBStatusUPP;
  170. typedef UniversalProcPtr DBResultHandlerUPP;
  171. #else
  172. typedef DBQueryDefProcPtr DBQueryDefUPP;
  173. typedef DBStatusProcPtr DBStatusUPP;
  174. typedef DBResultHandlerProcPtr DBResultHandlerUPP;
  175. #endif
  176.  
  177. enum {
  178.     uppDBCompletionProcInfo = kRegisterBased
  179.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(DBAsyncParmBlkPtr))),
  180.     uppDBQueryDefProcInfo = kPascalStackBased
  181.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  182.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long *)))
  183.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(QueryHandle))),
  184.     uppDBStatusProcInfo = kPascalStackBased
  185.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  186.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  187.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(OSErr)))
  188.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  189.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  190.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(short)))
  191.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DBType)))
  192.          | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(Ptr))),
  193.     uppDBResultHandlerProcInfo = kPascalStackBased
  194.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  195.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DBType)))
  196.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
  197.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  198.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  199.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(Ptr)))
  200.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(Handle)))
  201. };
  202.  
  203. #if GENERATINGCFM
  204. #define NewDBCompletionProc(userRoutine)        \
  205.         (DBCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBCompletionProcInfo, GetCurrentArchitecture())
  206. #define NewDBQueryDefProc(userRoutine)        \
  207.         (DBQueryDefUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBQueryDefProcInfo, GetCurrentArchitecture())
  208. #define NewDBStatusProc(userRoutine)        \
  209.         (DBStatusUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBStatusProcInfo, GetCurrentArchitecture())
  210. #define NewDBResultHandlerProc(userRoutine)        \
  211.         (DBResultHandlerUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBResultHandlerProcInfo, GetCurrentArchitecture())
  212. #else
  213. #define NewDBCompletionProc(userRoutine)        \
  214.         ((DBCompletionUPP) (userRoutine))
  215. #define NewDBQueryDefProc(userRoutine)        \
  216.         ((DBQueryDefUPP) (userRoutine))
  217. #define NewDBStatusProc(userRoutine)        \
  218.         ((DBStatusUPP) (userRoutine))
  219. #define NewDBResultHandlerProc(userRoutine)        \
  220.         ((DBResultHandlerUPP) (userRoutine))
  221. #endif
  222.  
  223. #if GENERATINGCFM
  224. #define CallDBCompletionProc(userRoutine, pb)        \
  225.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBCompletionProcInfo, (pb))
  226. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  227.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBQueryDefProcInfo, (sessID), (query))
  228. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  229.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBStatusProcInfo, (message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  230. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  231.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBResultHandlerProcInfo, (dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  232. #else
  233. /* (*DBCompletionUPP) cannot be called from a high-level language without the Mixed Mode Manager */
  234. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  235.         (*(userRoutine))((sessID), (query))
  236. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  237.         (*(userRoutine))((message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  238. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  239.         (*(userRoutine))((dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  240. #endif
  241. extern pascal OSErr InitDBPack(void )
  242.  FIVEWORDINLINE(0x3F3C, 0x0004, 0x303C, 0x0100, 0xA82F);
  243.  
  244. extern pascal OSErr DBInit(long *sessID, ConstStr63Param ddevName, ConstStr255Param host, ConstStr255Param user, ConstStr255Param passwd, ConstStr255Param connStr, DBAsyncParmBlkPtr asyncPB)
  245.  THREEWORDINLINE(0x303C, 0x0E02, 0xA82F);
  246.  
  247. extern pascal OSErr DBEnd(long sessID, DBAsyncParmBlkPtr asyncPB)
  248.  THREEWORDINLINE(0x303C, 0x0403, 0xA82F);
  249.  
  250. extern pascal OSErr DBGetConnInfo(long sessID, short sessNum, long *returnedID, long *version, Str63 ddevName, Str255 host, Str255 user, Str255 network, Str255 connStr, long *start, OSErr *state, DBAsyncParmBlkPtr asyncPB)
  251.  THREEWORDINLINE(0x303C, 0x1704, 0xA82F);
  252.  
  253. extern pascal OSErr DBGetSessionNum(long sessID, short *sessNum, DBAsyncParmBlkPtr asyncPB)
  254.  THREEWORDINLINE(0x303C, 0x0605, 0xA82F);
  255.  
  256. extern pascal OSErr DBSend(long sessID, Ptr text, short len, DBAsyncParmBlkPtr asyncPB)
  257.  THREEWORDINLINE(0x303C, 0x0706, 0xA82F);
  258.  
  259. extern pascal OSErr DBSendItem(long sessID, DBType dataType, short len, short places, short flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  260.  THREEWORDINLINE(0x303C, 0x0B07, 0xA82F);
  261.  
  262. extern pascal OSErr DBExec(long sessID, DBAsyncParmBlkPtr asyncPB)
  263.  THREEWORDINLINE(0x303C, 0x0408, 0xA82F);
  264.  
  265. extern pascal OSErr DBState(long sessID, DBAsyncParmBlkPtr asyncPB)
  266.  THREEWORDINLINE(0x303C, 0x0409, 0xA82F);
  267.  
  268. extern pascal OSErr DBGetErr(long sessID, long *err1, long *err2, Str255 item1, Str255 item2, Str255 errorMsg, DBAsyncParmBlkPtr asyncPB)
  269.  THREEWORDINLINE(0x303C, 0x0E0A, 0xA82F);
  270.  
  271. extern pascal OSErr DBBreak(long sessID, Boolean abort, DBAsyncParmBlkPtr asyncPB)
  272.  THREEWORDINLINE(0x303C, 0x050B, 0xA82F);
  273.  
  274. extern pascal OSErr DBGetItem(long sessID, long timeout, DBType *dataType, short *len, short *places, short *flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  275.  THREEWORDINLINE(0x303C, 0x100C, 0xA82F);
  276.  
  277. extern pascal OSErr DBUnGetItem(long sessID, DBAsyncParmBlkPtr asyncPB)
  278.  THREEWORDINLINE(0x303C, 0x040D, 0xA82F);
  279.  
  280. extern pascal OSErr DBKill(DBAsyncParmBlkPtr asyncPB)
  281.  THREEWORDINLINE(0x303C, 0x020E, 0xA82F);
  282.  
  283. extern pascal OSErr DBGetNewQuery(short queryID, QueryHandle *query)
  284.  THREEWORDINLINE(0x303C, 0x030F, 0xA82F);
  285.  
  286. extern pascal OSErr DBDisposeQuery(QueryHandle query)
  287.  THREEWORDINLINE(0x303C, 0x0210, 0xA82F);
  288.  
  289. extern pascal OSErr DBStartQuery(long *sessID, QueryHandle query, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  290.  THREEWORDINLINE(0x303C, 0x0811, 0xA82F);
  291.  
  292. extern pascal OSErr DBGetQueryResults(long sessID, ResultsRecord *results, long timeout, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  293.  THREEWORDINLINE(0x303C, 0x0A12, 0xA82F);
  294.  
  295. extern pascal OSErr DBResultsToText(ResultsRecord *results, Handle *theText)
  296.  THREEWORDINLINE(0x303C, 0x0413, 0xA82F);
  297.  
  298. extern pascal OSErr DBInstallResultHandler(DBType dataType, DBResultHandlerUPP theHandler, Boolean isSysHandler)
  299.  THREEWORDINLINE(0x303C, 0x0514, 0xA82F);
  300.  
  301. extern pascal OSErr DBRemoveResultHandler(DBType dataType)
  302.  THREEWORDINLINE(0x303C, 0x0215, 0xA82F);
  303.  
  304. extern pascal OSErr DBGetResultHandler(DBType dataType, DBResultHandlerUPP *theHandler, Boolean getSysHandler)
  305.  THREEWORDINLINE(0x303C, 0x0516, 0xA82F);
  306.  
  307. extern pascal OSErr DBIdle(void )
  308.  THREEWORDINLINE(0x303C, 0x00FF, 0xA82F);
  309.  
  310. #endif
  311.  
  312. #if PRAGMA_ALIGN_SUPPORTED
  313. #pragma options align=reset
  314. #endif
  315.  
  316. #if PRAGMA_IMPORT_SUPPORTED
  317. #pragma import off
  318. #endif
  319.  
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323.  
  324. #endif /* __DATABASEACCESS__ */
  325.  
  326.